const HomeHttp = require("../../utils/Home")
const Http = require("../../utils/http")
Page({
  data: {
    val: "",
    isSearch: true,
    isClear: false,
    detail: []
  },
  getInput: function (e) {
    var keyword = e.detail.value;
    console.log(keyword)

    this.setData({
      val: e.detail.value,
    })
    if (this.data.val.length > 0) {
      this.setData({
        isSearch: false,
        isClear: true
      })
      var url = `http://127.0.0.1:7001/search?keyword=${keyword}`
      wx.request({
        url,
        data: {},
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (res) => {
          var arr = res.data.res;
          var detail = [];
          arr.forEach(item => {
            var { _id, price, name, Count, isLike, pic, title } = item;
            detail.push({
              _id,
              pic,
              name: name.slice(3, 18),
              Count,
              isLike,
              price,
              title
            })
            this.setData({
              detail
            })
          })
        },
      });
    } else {
      this.setData({
        isSearch: true,
        isClear: false,
        val: "",
        detail:""
      })
    }
  },
  // async onSubmit(event) {
  //   console.log(event.detail.value.name)
  // }
})